﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register Src="~/Views/Lightbox/LightboxManager.ascx" TagName="lightboxmanager" TagPrefix="uc" %>
<%@ Register Src="~/Views/Lightbox/LightboxControl.ascx" TagName="lightboxcontrol" TagPrefix="uc" %>


<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	LIGHTBOXES 
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
    VietImage.Roles.RegisteredUserRole role = (VietImage.Roles.RegisteredUserRole)Session["Role"];
    if (role != null)
    {
        //lightboxmanger1.ViewData = ViewData;
        %>
        <uc:lightboxmanager ID="lightboxmanger1" runat="server" />
        <%
    }
 %>

<div id="lightboxcontrol">
<uc:lightboxcontrol ID="lightboxcontrol1" runat="server" />
</div>






    
<script>

    $("#lightboxname").submit(function () {
        var type = $("#type").val();
        var lbid = $("#cmbLightboxList").val();
        var lbname = $("#lbname").val();
        var id = "";
        if (type == "rename") {
            id = "&id=" + lbid;
        }
        var d = "type=" + type + "&name=" + lbname + id;
        ajaxalertresult('<%= Url.Action("CreateOrRenameLightbox", "Lightbox") %>', d, function () {
            loadLightboxList(lbid);
            $("#frmlbn").hide("fast");
        });
        return false;
    });
    $("#renamelightbox").click(function () {
        var lbid = $("#cmbLightboxList").val();
        if (lbid == 0) {
            alert("Bạn chưa chọn Lightbox!");
            return;
        }
        $("#frmlbn").show("fast");
        $("#type").val("rename");
        $("#mbtnlightboxname").html("Đổi tên");
    });
    $("#createlightbox").click(function () {
        $("#frmlbn").show("fast");
        $("#type").val("create");
        $("#mbtnlightboxname").html("Tạo mới");
    });
    $("#deletelightbox").click(function () {
        var lbid = $("#cmbLightboxList").val();
        if (lbid == "") {
            alert("Bạn chưa chọn Lightbox!");
            return;
        }
        var d = "id=" + lbid;
        ajaxalertresult('<%= Url.Action("DeleteLightbox", "Lightbox") %>', d, function () {
            loadLightboxList(0);
        });
    });
    $("#closelbn").click(function () {
        $("#frmlbn").hide("fast");
    });
    $(".checkbox").click(function () {
        if ($(this).hasClass("imgcheckbox")) {
            if ($(this).children(".checked").css("display") == "none") {
                $(this).parents("tr").find(".checked").fadeIn("normal");
            }
            else {
                $(this).parents("tr").find(".checked").fadeOut("normal");
            }
        }
        else {
            $(this).children(".checked").fadeToggle("normal");
        }
        return false;
    });
    $(".imgcheckbox").click(function () {
        return false;
    });
    $("#selectall").click(function () {
        $(".checkbox").children(".checked").fadeIn("normal");
    });
    $("#deselectall").click(function () {
        $(".checkbox").children(".checked").hide();
    });
    $("#cmbLightboxList").change(function (e) {
        $(this).attr('disabled', 'disabled');
        var id = $(this).val();
        viewLightBox(id);
    });

    function loadLightboxList(lbid) {
        if (lbid == null || isNaN(lbid)) {
            lbid = 0;
        }
        $.ajax({
            url: "/GetList/MyLightboxes",
            data: { id: lbid },
            type: "POST",
            success: function (data) {
                $("#cmbLightboxList").html(data);
                $("#cmbLightboxList2").html(data);
            }
        });
    }

    function viewLightBox(id) {
        $.ajax({
            url: "/Lightbox/Detail",
            data: { id: id },
            type: "POST",
            success: function (data) {
                $("#cmbLightboxList").removeAttr('disabled');
                $("#lightboxcontrol").html(data);
                Website.run();
            }
        });
    }
</script>
</asp:Content>
